﻿using Entity;
using IRealize;
using Microsoft.AspNetCore.Mvc;
using Realize;

namespace WebApplication9.Controllers.Recruit_Manage.ZW
{
    public class EMR_SUDController : Controller
    {
        private readonly IConfiguration configuration;

        public EMR_SUDController(IConfiguration configuration)
        {
            this.configuration = configuration;
        }
        //EMR表删改查
        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public async Task<ActionResult> Select_EMR(int CurrentPage, int PageSize)
        {
            IEMR emr = new EMR();
            List<Engage_Major_Release> zhi = await emr.select_EMR(configuration["SqlServer"]);
            List<Engage_Major_Release> zhi2 = zhi.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList();
            PagedViewModel<Engage_Major_Release> cc = new PagedViewModel<Engage_Major_Release>() { itemas = zhi2, total = zhi.Count };
            return Ok(new
            {
                list = cc
            });
        }

        [HttpGet]
        public IActionResult Upd(string id)
        {
            ViewBag.TitleId = id;
            return View();
        }

        [HttpGet]
        public async Task<IActionResult> selectById_EMR(string id)
        {
            IEMR emr = new EMR();
            Engage_Major_Release emru = await emr.selectById_EMR(id, configuration["SqlServer"]);
            return Ok(new
            {
                zhi = emru
            });
        }

        [HttpGet]
        public async Task<IActionResult> Update(int mre_id, short human_amount, string engage_type, DateTime deadline, string changer, DateTime change_time, string major_describe, string engage_required)
        {
            IEMR emr = new EMR();
            int result = await emr.update_EMR(mre_id, human_amount, engage_type, deadline, changer, change_time, major_describe, engage_required, configuration["SqlServer"]);
            if (result > 0)
            {
                return Ok(new
                {
                    zhi = "ok"
                });
            }
            else
            {
                return Ok(new
                {
                    zhi = "nook"
                });
            }

        }

        public async Task<IActionResult> Delete(int id)
        {
            IEMR emr = new EMR();
            int result = await emr.delete_EMR(id, configuration["SqlServer"]);
            if (result > 0)
            {
                return Ok(new
                {
                    zhi = "ok"
                });
            }
            else
            {
                return Ok(new
                {
                    zhi = "nook"
                });
            }
        }

    }
}
